package com.liming.service.redis.impl;

import com.liming.service.redis.RedisClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author liming
 * @date 2025/3/19
 */
@Slf4j
@Service
@ConditionalOnClass(RedisTemplate.class)
@AllArgsConstructor
public class RedisClientImpl implements RedisClient {

    private final RedisTemplate<String, Object> redisTemplate;

    @Override
    public void valueSet(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    @Override
    public void valueSet(String key, Object value, long expireTime, TimeUnit unit) {
        redisTemplate.opsForValue().set(key, value, expireTime, unit);
    }

    @Override
    public Object valueGet(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public void zSetAdd(String key, Object value, double score) {
        redisTemplate.opsForZSet().add(key, value, score);
    }

    @Override
    public Set<Object> zSetRange(String key, long start, long end) {
        return redisTemplate.opsForZSet().range(key, start, end);
    }

    @Override
    public Boolean delete(String key) {
        return redisTemplate.delete(key);
    }
}
